home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: boukanov@sentef1.fi.uib.no (Igor Boukanov)
- Newsgroups: comp.std.c++
- Subject: Function object operator() is too anonymous.
- Date: 28 Mar 1996 20:27:18 GMT
- Organization: Fysisk institutt, Universitetet i Bergen
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <4jerpo$bvb@ugress.uib.no>
- NNTP-Posting-Host: taumet.eng.sun.com
- Keywords: C++, function object
- X-Nntp-Posting-Host: sentef1.fi.uib.no
- X-Newsreader: TIN [version 1.2 PL2]
- Content-Length: 1331
- X-Lines: 37
- Originator: clamage@taumet
-
- I noticed that that it impossible to write Function object class
- (DWP 20.3) that can be used for example as Arithmetic operation object
- and Predicate object in the same time, because both require operator()
- that can not be overloaded! So why do not have instead of one anonymous
- operator() a set of function obect methods like
- unary_operation, binary_operation, predicate, comparison
- and each function from algorithm.h will call correspondent method.
- For example, find_if will call predicate method of function object and
- transform will call unary_operation or binary_operation
- instead of operator().
-
- In this case one can write:
-
- class F {
- ...
- bool predicate(int); // instead of bool operator()(int);
- int unary_operation(int); // instead of int operator()(int);
- int binary_operation(int, int); // instead of int operator()(int, int);
- bool comparison(int, int); // instead of bool operator()(int, int);
- };
-
- and somewhere use F:
-
- vector<int> v1, v2;
- F f;
-
- ...
- std::find_if(v1.begin(), v1.end(), f);
- // f.predicate(int) will be called
- std::transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), f);
- // f.binary_operation(int, int) will be called
- std::equal(v1.begin(), v1.end(), v2.begin(), f);
- // f.comparison(int, int) will be called
-
- --
- With best regards,
- Igor Boukanov (igor.boukanov@fi.uib.no).
-
-
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-